package com.lindroy.androidplayer.ui.adapter

import androidx.lifecycle.LifecycleOwner
import androidx.recyclerview.widget.DiffUtil
import com.lindroy.androidplayer.base.adapter.BasePagingAdapter
import com.lindroy.androidplayer.databinding.CoinRankItemBinding
import com.lindroy.androidplayer.viewmodels.CoinRankingItemViewModel

/**
 * @author Lin
 * @date 2022/2/16
 * @function 积分排行榜
 */
class CoinRankingAdapter(owner: LifecycleOwner) :
    BasePagingAdapter<CoinRankingItemViewModel, CoinRankItemBinding>(owner,
        object : DiffUtil.ItemCallback<CoinRankingItemViewModel>() {

            override fun areItemsTheSame(
                oldItem: CoinRankingItemViewModel,
                newItem: CoinRankingItemViewModel
            ) = oldItem.userId == newItem.userId

            override fun areContentsTheSame(
                oldItem: CoinRankingItemViewModel,
                newItem: CoinRankingItemViewModel
            ): Boolean = oldItem.rank == newItem.rank

        }) {
    override fun CoinRankItemBinding.onBindViewHolder(
        item: CoinRankingItemViewModel?,
        position: Int
    ) {
        vm = item
    }
}